import carousel from "../../common/api/carousel"

const main = {
	state: {
		movies: [],
		searchtrailers: []
	},
	mutations: {
		SET_MOVIES: (state, movies) => {
			state.movies = movies
		},
		SET_SEARCHTRAILERS: (state, searchtrailers) => {
			state.searchtrailers = searchtrailers
		}
	},
	actions: {
		//轮播图
		GetCarousel({
			commit
		}) {
			return new Promise((reslove, reject) => {
				carousel.Carousel().then(data => {
					reslove(data)
				}).catch(err => {
					reject(err)
				})
			})
		},
		// 热门超英
		GetSuperHero({
			commit
		}) {
			return new Promise((reslove, reject) => {
				carousel.SuperHero().then(data => {
					commit("SET_MOVIES", data.data);
					reslove(data)
				}).catch(err => {
					reject(err)
				})
			})
		},
		// 热门预告
		GetTrailer() {
			return new Promise((reslove, reject) => {
				carousel.Trailer().then(data => {
					reslove(data)
				}).catch(err => {
					reject(err)
				})
			})
		},
		// 猜你喜欢
		GetGuessULike() {
			return new Promise((reslove, reject) => {
				carousel.GuessULike().then(data => {
					reslove(data)
				}).catch(err => {
					reject(err)
				})
			})
		},

		// 获取影片详情
		GetSearchTrailer({
			commit,
			state
		}, id) {
			return new Promise((reslove, reject) => {
				carousel.SearchTrailer(id).then(data => {
					reslove(data)
				}).catch(err => {
					reject(err)
				})
			})
		},
		// 查询演职人员
		GetStaff({
			commit,
			state
		}, id) {
			return new Promise((reslove, reject) => {
				carousel.Staff(id).then(data => {
					reslove(data)
				}).catch(err => {
					reject(err)
				})
			})
		},
	}
}

export default main;
